package com.example.commons.models

import com.example.commons.serialization.DateTimeSerializer
import kotlinx.serialization.Serializable
import java.time.LocalDateTime

@Serializable
data class AppVersion(
    var id: Long = 0L,
    var applicationId: String = "",
    var versionCode: Int = 0,
    var versionName: String = "",
    var description: String = "",
    var variantName: String = "",
    var outputFile: String = "",
//    var path: String = "", // 存储路径

    /**
     * 平台类型
     * android/ios/window/macos/...
     */
    var platformType: String = "",

    @Serializable(DateTimeSerializer::class)
    var createdAt: LocalDateTime? = LocalDateTime.now()
)

/**
 * 参考apk的out-metadata.json
 */
@Serializable
data class ApkInfo(
    val applicationId: String,
    val artifactType: ArtifactType,
    val elementType: String,
    val elements: List<Element>,
    val variantName: String,
    val version: Int,
    /**
     * apk 的描述信息
     */
    val description: String = ""
) {
    val appVersion: AppVersion get() = AppVersion(
        0,
        applicationId,
        elements[0].versionCode,
        elements[0].versionName,
        description,
        variantName,
        elements[0].outputFile,
//        "",
        "",
    )
}

@Serializable
data class ArtifactType(
    val kind: String,
    val type: String
) {
    val platformType: String
        get() {
            if ("Apk".equals(type, true)) {
                return "android"
            }
            return "other"
        }
}

@Serializable
data class Element(
    val attributes: List<String>,
    val filters: List<String>,
    val outputFile: String,
    val type: String,
    val versionCode: Int,
    val versionName: String
)